package com.whl.common.constants;

public class EnumType {
	public enum ResponseType implements IEnumType<Integer> {
		NOT_AUTH(401, "末认证"), 
		NOT_PERMISS(403, "末授权"), 
		FAIL(400, "失败"), 
		FAIL_RELOAD(600, "失败刷新重试"), 
		SUCCESS(200, "成功"),
		;

		private ResponseType(Integer code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private Integer code;
		private String msg;

		@Override
		public Integer code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
	}
	public enum AppType implements IEnumType<String> {

		admin("admin", "运营后台"), 
		client("client", "电脑客户端"),
		;

		private AppType(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private String code;
		private String msg;

		@Override
		public String code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}

	}
	
	public enum TerminalType implements IEnumType<String> {

		COMPUTER("computer", "电脑"), 
		MOBILE("mobile", "手机"),
		;

		private TerminalType(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private String code;
		private String msg;

		@Override
		public String code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}

	}
	
	public enum PayStatus implements IEnumType<String> {
		WAIT("wait", "待支付"), 
		SUCCESS("success", "支付成功"), 
		FAIL("fail", "支付失败"),
		PREFUND("prefund","部份退款"),
		REFUND("refund","退款"),
		;

		private PayStatus(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private String code;
		private String msg;

		@Override
		public String code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
	}


	public enum RefundFlag implements IEnumType<Integer> {
		APPLY(1, "申请退款"),
		NO(0, "未退款"),
		;

		private RefundFlag(Integer code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private Integer code;
		private String msg;

		@Override
		public Integer code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
	}

	public enum RefundStatus implements IEnumType<String> {
		APPLY("apply", "申请退款"),
		DEALING("dealing", "退款中"),
		FAIL("fail", "退款失败"),
		SUCCESS("success", "退款成功"),
		NO("no", "无退款"),
		;

		private RefundStatus(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private String code;
		private String msg;

		@Override
		public String code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
	}


	public enum OrderState implements IEnumType<String> {

		PAY("pay", "待支付"),
		DELIVERY("delivery","待发货"),
		RECEIVE("receive","待收货"),
		FINISH("finish","已完成"),
		CANCEL("cancel","已取消"),
		;

		private OrderState(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private String code;
		private String msg;

		@Override
		public String code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
	}


	public enum AccountOptionType implements IEnumType<Integer> {

		channelInCome(1, "分佣收入"),
		;

		private AccountOptionType(Integer code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private Integer code;
		private String msg;

		@Override
		public Integer code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
	}


	public enum activityUserRole implements IEnumType<Integer> {

		activityOwner(1, "团长"),
		activityJoiner(2, "团员")
		;

		private activityUserRole(Integer code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private Integer code;
		private String msg;

		@Override
		public Integer code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
	}

	
	public enum TransactionChannel implements IEnumType<String> {

		WEIXIN("weixin", "微信"), 
		;

		private TransactionChannel(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private String code;
		private String msg;

		@Override
		public String code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
	}

	public enum CommentTarget implements IEnumType<String> {

		GOODS("goods", "商品"),
		INFOMATION("infomation", "资讯"),
		;

		private CommentTarget(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private String code;
		private String msg;

		@Override
		public String code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
	}
	
	/**
	 * 团购用户角色
	 * @author tommy
	 *
	 */
	public enum BuyGroupUserRole implements IEnumType<Integer> {

		LEADER(1, "团长"), 
		MEMBER(2, "团员"), 
		;

		private BuyGroupUserRole(Integer code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private Integer code;
		private String msg;

		@Override
		public Integer code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
		
	}
	
	public enum BuyRecordStatusType implements IEnumType<Integer> {

		NO_PAY(-1, "团长未支付"), 
		GROUPING(0, "未成团(进行中)"), 
		SUCESS(1, "已成团"), 
		FAIL(2, "拼团失败"), 
		;

		private BuyRecordStatusType(Integer code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private Integer code;
		private String msg;

		@Override
		public Integer code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
		
	}
	
	/**
	 * 拼团订单状态
	 * @author tommy
	 *
	 */
	public enum BuyGroupStatusOrderType implements IEnumType<Integer> {
		
		PAY(1, "未支付"), 
		PAYED(2, "已支付"), 
		CANNCEL(3,"已取消")
		;
		
		private BuyGroupStatusOrderType(Integer code, String msg) {
			this.code = code;
			this.msg = msg;
		}
		
		private Integer code;
		private String msg;
		
		@Override
		public Integer code() {
			return code;
		}
		
		@Override
		public String msg() {
			return msg;
		}
		
	}
	
	/**
	 * 订单类型
	 * @author tommy
	 *
	 */
	public enum OrderType implements IEnumType<Integer> {

		ORDINARY(1, "普通订单"), 
		GROUP(2, "团购订单"), 
		;

		private OrderType(Integer code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private Integer code;
		private String msg;

		@Override
		public Integer code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
		
	}
	
	/**
	 * 收货方式
	 * @author tommy
	 *
	 */
	public enum DeliverType implements IEnumType<String> {

		SELF("self", "自提点"), 
		DELIVER("deliver", "快递"), 
		;

		private DeliverType(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private String code;
		private String msg;

		@Override
		public String code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
		
	}
	
	/**
	 * 分享类型
	 * @author tommy
	 *
	 */
	public enum ShareOptionType implements IEnumType<Integer> {

		MINI(0, "小程序"), 
		GOODS(1, "商品"), 
		;

		private ShareOptionType(Integer code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private Integer code;
		private String msg;

		@Override
		public Integer code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
		
	}
	
	
	public enum IOFlagType implements IEnumType<String> {

		IN("+", "收入"), 
		OUT("-", "支出"), 
		;

		private IOFlagType(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		private String code;
		private String msg;

		@Override
		public String code() {
			return code;
		}

		@Override
		public String msg() {
			return msg;
		}
		
	}
	public enum TradeType implements IEnumType<String> {
		
		PAY("pay", "支付"), 
		REFUND("refund", "退款"), 
		WITHDRAWAL("withdrawal", "退款"), 
		;
		
		private TradeType(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}
		
		private String code;
		private String msg;
		
		@Override
		public String code() {
			return code;
		}
		
		@Override
		public String msg() {
			return msg;
		}
		
	}
	
public enum SettleStatusType implements IEnumType<String> {
		
		WAIT("wait", "待结算"), 
		FINISH("finish", "已结算"), 
		;
		
		private SettleStatusType(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}
		
		private String code;
		private String msg;
		
		@Override
		public String code() {
			return code;
		}
		
		@Override
		public String msg() {
			return msg;
		}
		
	}



	public enum WithdrawalType implements IEnumType<String> {
		
		COMMISSION("commission", "佣金"), 
		BALANCE("balance", "余额"), 
		;
		
		private WithdrawalType(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}
		
		private String code;
		private String msg;
		
		@Override
		public String code() {
			return code;
		}
		
		@Override
		public String msg() {
			return msg;
		}
		
	}
	
	public enum WithdrawalStatus implements IEnumType<String> {
		
		APPLY("apply", "申请"), 
		FINISH("finish", "已打款"), 
		REJECT("reject", "已拒绝"), 
		;
		
		private WithdrawalStatus(String code, String msg) {
			this.code = code;
			this.msg = msg;
		}
		
		private String code;
		private String msg;
		
		@Override
		public String code() {
			return code;
		}
		
		@Override
		public String msg() {
			return msg;
		}
		
	}
	

	public static <T, D> T getByCode(Class<T> clazz, D value) {
		T[] enumConstants = clazz.getEnumConstants();
		for (int i = 0; i < enumConstants.length; i++) {
			if (((IEnumType<?>) enumConstants[i]).code().equals(value)) {
				return enumConstants[i];
			}
		}
		return null;
	}

}
